<template>
  <div class="merchant-setting views-container">
    <div class="wlm-form">
      <div class="wlm-form-header">缓存模块</div>
      <div class="wlm-form-content">
        <!-- <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll"  @change="handleCheckAllChange">全选</el-checkbox>
            <div style="margin:15px 15px 15px 60px">
                 <el-checkbox-group v-model="model" @change="handleCheckAllChange">
                    <el-checkbox :label="'user'">用户模块</el-checkbox>
                    <el-checkbox :label="'goods'">商品模块</el-checkbox>
                    <el-checkbox :label="'order'">订单模块</el-checkbox>
                    <el-checkbox :label="'diy'">页面模块</el-checkbox>
                    <el-checkbox :label="'setting'">设置模块</el-checkbox>
                    <el-checkbox :label="'asy'">任务模块</el-checkbox>
                    <el-checkbox :label="'luck'">抽奖模块</el-checkbox>
                    <el-checkbox :label="'message'">消息模块</el-checkbox>
                    <el-checkbox :label="'address'">地址模块</el-checkbox>
                    <el-checkbox :label="'log'">日志模块</el-checkbox>
                </el-checkbox-group>
            </div> -->
        <el-checkbox
          :indeterminate="isIndeterminate"
          v-model="checkAll"
          @change="handleCheckAllChange"
        >全选</el-checkbox>
        <div style="margin:15px 15px 15px 60px">
        <el-checkbox-group
          v-model="model"
          @change="handleCheckedCitiesChange"
        >
          <el-checkbox :label="item.label" v-for="(item,index) in modelAll" :key="index">{{item.name}}</el-checkbox>

        </el-checkbox-group>
        </div>
        <el-button
          type="primary"
          @click="clickBtn"
        >清除缓存</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import {
  clearRedis
} from '@/api/setting'
export default {
  data() {
    return {
      modelAll: [{ label: 'user', name: '用户模块' }, { label: 'goods', name: '商品模块' }, { label: 'order', name: '订单模块' }, { label: 'diy', name: '页面模块' }, { label: 'setting', name: '设置模块' },
        { label: 'asy', name: '任务模块' }, { label: 'luck', name: '抽奖模块' }, { label: 'message', name: '消息模块' }, { label: 'address', name: '地址模块' }, { label: 'log', name: '日志模块' },{label:'data',name:'数据模块'}],
      checkAll: false,
      isIndeterminate: false,
      model: []
    }
  },
  methods: {
    clickBtn() {
      clearRedis({ model: this.model }).then(res => {
        const { data: { msg, code } } = res
        if (code == 1) {
          this.$message.success('操作成功')
        } else {
          this.$message.error(msg)
        }
      })
    },
    handleCheckAllChange(val) {
      this.model = val ? this.modelAll.map(item => item.label) : []
      this.isIndeterminate = false
    },
    handleCheckedCitiesChange(value) {
      const checkedCount = value.length
      this.checkAll = checkedCount === this.modelAll.length
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.modelAll.length
    }
  }
}
</script>
<style lang="scss" scoped>
.edit-title {
  font-size: 15px;
}
</style>
